<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class Debugger
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {

//        dd($request->getPathInfo());
        $path = $request->getPathInfo();
        $allowPath = [
            '/cjzdebug',
            '/_debugbar/open'
        ];
        if(
            !in_array($path,$allowPath)
            && $request->input('cjzdebug')!=1
            && config('app.env') != 'local'
        ){
            \Debugbar::disable();
        }
        return $next($request);
    }
}
